package com.xzj.common.knife4j.config;

import com.xzj.common.knife4j.properties.Knife4jProperties;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

@Slf4j
@Configuration
@EnableConfigurationProperties(Knife4jProperties.class)
public class Knife4jConfig {

    @Value("${spring.application.name}")
    private String applicationName;

    @Resource
    private Knife4jProperties knife4jProperties;

    @Bean
    public OpenAPI springShopOpenAPI() {
        Map<String, String> contact = knife4jProperties.getContact();
        return new OpenAPI()
            // 接口文档标题
            .info(new Info().title(knife4jProperties.getTitle())
                // 接口文档描述
                .description(knife4jProperties.getDescription())
                // 接口文档版本
                .version("v1.0")
                // 开发者联系方式
                .contact(new Contact().name(contact.get("name")).url(contact.get("url")).email(contact.get("email"))))
            .externalDocs(new ExternalDocumentation()
                // 额外补充说明
                .description("Github example code")
                // 额外补充链接
                .url("https://github.com/Flying9001/springBootDemo/demo-knife4j-openapi3"));
    }
}
